from flask import current_app, send_from_directory, Blueprint, render_template
from flask_login import login_required
from app.models.report import Report

bp = Blueprint('site', __name__)


@bp.route('/')
@login_required
def index():
    return render_template('admin/site/index.html')


@bp.route('/uploads/<path:filename>')
def get_image(filename):
    return send_from_directory(current_app.config['BLUELOG_UPLOAD_PATH'], filename)


@bp.route('/preview/<int:id>')
def report_preview(id):
    model = Report.query.get_or_404(id)
    return render_template('admin/site/preview.html', model=model)
